const chalk = require('chalk');
const prompts = require('prompts');
const { isStringAndHasLength, dealfileObject } = require('../../helper.js');
const { find11Handler } = require('./find11Handler.js');

/**
 * 输出文件
 */
async function export11FilePath(dealfile) {
    const res = await prompts([
    {
        type: 'text',
        name: 'exportPath',
        message: `请输入要${chalk.red('输出')}的文件路径`+
        `${chalk.red('--不输入默认执行作用域下的 aci18n_ch_11.txt 文件')} \n`
    }])
    if (isStringAndHasLength(res.exportPath)) {
        find11Handler({ exportFile: res.exportPath, fileOrDirString: dealfile });
    } else {
        find11Handler({ exportFile: null, fileOrDirString: dealfile });
    }
}


/**
 * 查找 intl.get('11') 的中文 功能
 */
async function findintl11() {
    const res =  await prompts([dealfileObject])
    if (isStringAndHasLength(res.dealfile)) {
        export11FilePath(res.dealfile)
    } else {
        console.log(chalk.red(`您忘记输入查找路径啦！`));
    }
}

module.exports = {
    findintl11
}